﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Runda.EShop.Common.Utility;

namespace Runda.EShop.Service.Warning
{
    public class InnerService
    {
        private List<Thread> ThreadList = null;//工作线程列表
        private bool RunningRead = true;//标识读取数据

        public InnerService()
        {
            this.ThreadList = new List<System.Threading.Thread>();
            //添加获取数据线程
            this.ThreadList.Add(new System.Threading.Thread(test));
        }

        public void Start()
        {
            if ((!RunningRead))
                return;

            RunningRead = true;
            foreach (System.Threading.Thread thread in this.ThreadList)
            {
                //启动所有线程
                thread.Start();
                System.Threading.Thread.Sleep(100);
            }
        }

        public void Stop()
        {
            RunningRead = false;

            System.Threading.Thread.Sleep(1000);

            foreach (System.Threading.Thread thread in this.ThreadList)
            {
                try
                {
                    thread.Abort();
                }
                catch
                {
                }
            }
        }

        public void test()
        { 
            while (RunningRead)
            {
                try
                {
                    
                }
                catch (Exception ee)
                {
                    LogHelper.Write(string.Format("错误: {0}", ee));
                }

                DateTime tommorow = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day + 1, 23, 0, 0);
                System.Threading.Thread.Sleep(tommorow.Subtract(DateTime.Now));
            }
        }
    }
}
